<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
    String contextPath = (String) request.getContextPath();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css"
	href="<%=contextPath%>/js/jquery-easyui-1.3/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
	href="<%=contextPath%>/css/rs.css">
<link rel="stylesheet" type="text/css"
	href="<%=contextPath%>/js/jquery-easyui-1.3/themes/icon.css">
<script type="text/javascript"
	src="<%=contextPath%>/js/jquery-easyui-1.3/jquery-1.7.2.min.js"></script>
<script type="text/javascript"
	src="<%=contextPath%>/js/jquery-easyui-1.3/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="<%=contextPath%>/js/jquery-easyui-1.3/locale/easyui-lang-zh_CN.js"></script>
<script language="javascript">
var cur_pageSize=10;
var cur_pageNumber=1;

	$(function() {
		$('#wndAdd').window({closed:true});

		//保存
		$("#bt_submit").click(function(){
			$("#addForm").form('submit',{
				url:'<%=contextPath%>/userContract/userContract.do?method=save',
				onSubmit:function(){
					return validateForm();
				},		
				success:function(data){
					var data = eval('(' + data + ')');  
					$.messager.alert('提示',data.msg);
					if(data.flag=='success'){
					$("#addForm").form('clear');
					$('#wndAdd').window('close');
					$('#dataTable').datagrid('reload');
					}
				}
			});
		});
		//关闭新增窗口
		$("#bt_close").click(function(){
			$('#wndAdd').window('close');
		});
		
		$('#dataTable').datagrid({
			title : '病人联系信息',
			height : 500,
			nowrap : true,
			autoRowHeight : false,
			striped : true,
			collapsible : false,
			url : '<%=contextPath%>/userContract/userContract.do?method=listData&pageNumber='+cur_pageNumber+'&pageSize='+cur_pageSize,
			remoteSort : false,
			idField : 'id',
							columns : [ [
									{
										field : 'ck',
										checkbox : true
									},
									{
										field : 'id',
										title : 'ID',
										width : 80,
										sortable : true
									},
									{
										field : 'user_id',
										title : '用户ID',
										width : 50,
										sortable : true										 
									},
									{
										field : 'mobile_no',
										title : '手机号',
										width : 120,
										sortable : true
									},
									{
										field : 'email',
										title : 'Email',
										width : 220,
										sortable : true
									},
									{
										field : 'name',
										title : '姓名',
										width : 90,
										sortable : true 
									},
									{
										field : 'sex',
										title : '性别',
										width : 90,
										sortable : true,
										formatter : function(value, data, index) {
											return data.sex=='m'?'男':'女';
										}
									},
									{
										field : 'age',
										title : '年龄',
										width : 30,
										sortable : true 
									},
									{
										field : 'id_card_no',
										title : '身份证号',
										width : 70,
										sortable : true 
									},
									{
										field : 'address',
										title : '地址',
										width : 100,
										sortable : true 
									},
									{
										field : 'reg_time',
										title : '预约日期',
										width : 70,
										sortable : true ,
										formatter : function(value, data, index) {
											return (data.reg_time.year + 1900)
													+ "-"
													+ (data.reg_time.month + 1)
													+ "-"
													+ (data.reg_time.date)
													;
										}
									},
									{
										field : 'update_time',
										title : '更新时间',
										width : 70,
										sortable : true 
									}, 
									{
										field : 'opt',
										title : '操作',
										width : 100,
										align : 'center',
										rowspan : 2,
										formatter : function(value, row,index) {
											return '<a style="color:red" href="#" mce_href="#" onClick="editSingle('+row.id+')">编辑</a>';
										}
									} ] ],

							pagination : true,
							rownumbers : true,

							toolbar : [ {
								id : 'btncut',
								text : '删除	',
								iconCls : 'icon-cut',
								handler : function() {
									//$(function() {
										var rows = $('#dataTable').datagrid('getSelections');
										if (!rows || rows.length == 0) {
											$.messager.alert('提示',
													'请选择要删除的记录!', 'info');
											return;
										}
										var parm;
										//循环给提交删除参数赋值
										$.each(rows, function(i, n) {
											if (i == 0) {
												parm = "id=" + n.id;
											} else {
												parm += "&id=" + n.id;
											}
										});
										$.messager.confirm(
														'提示',
														'是否删除选中的记录?',
														function(r) {
															if (!r) {
																return;
															}
															//提交
															$.post('<%=contextPath%>/userContract/userContract.do?method=delete',
																	parm,
																	function(msg) {
																		//重新加载当前页
																		$('#dataTable').datagrid(msg.rows);
																	});
														});

									//});
								}
							} ]
						});
		 
		var p = $('#dataTable').datagrid('getPager');
		$(p).pagination( {
			onRefresh : function() {
				var parm;
				parm='pageNumber=1&pageSize='+cur_pageSize;
				$.post('<%=contextPath%>/userContract/userContract.do?method=listData',
						parm,
						function(msg) {
							$('#dataTable').datagrid('clearSelections');
							//重新加载当前页
							$('#dataTable').datagrid(msg.rows);
						}
					);
			},
		    onSelectPage:function(pageNumber,pageSize){
				cur_pageSize=pageSize;
				cur_pageNumber=pageNumber;
				var parm;
				$('#dataTable').datagrid('clearSelections');
				parm='pageNumber='+pageNumber+'&pageSize='+pageSize;
				$.post('<%=contextPath%>/userContract/userContract.do?method=listData',
						parm,
						function(msg) {
							//重新加载当前页
							$('#dataTable').datagrid(msg.rows);
						}
					);
		    }
		});	
	});
	
	
	function deleteSingle(id){
		var parm;
		parm ='id='+id + '&pageNumber='+cur_pageNumber+'&pageSize='+cur_pageSize;
		$.messager.confirm(
				'提示',
				'确定删除?',
				function(r) {
					if (!r) {
						return;
					}
				$.post('<%=contextPath%>/userContract/userContract.do?method=delete',
				parm,
				function(msg) {
					 $('#dataTable').datagrid(msg.rows);
				});
		});
	}
	//编辑
	function editSingle(id){
		$("#addForm").form('clear');
		$.ajax({
			url:"<%=contextPath%>/userContract/userContract.do?method=edit&id="+id,
			type:"post",
			success:function(data){
				var data = eval('('+data+')');
				$("#userId").attr("disabled","disabled");
				$("#id").val(data.id);
				$("#userId").val(data.userId);
				$("#mobileNo").val(data.mobileNo);
				$("#email").val(data.email);
				$("#name").val(data.name);
				$("#sex").combobox('select',data.sex);
				$("#idCardNo").val(data.idCardNo);
				$("#age").val(data.age);
				$("#address").val(data.address);
			}
		});
		$('#wndAdd').window({
			title:"编辑",
			closed:false,
			width : 470,
			height : 240,
			top:($(window).height()-240)*0.5,   
            left:($(window).width()-470)*0.5,
			 
			onload:function(){
			 
			},
			modal : true
		});
	}

	function validateForm(){
		var msg = "";
		//电话
		if($.trim($("#mobileNo").val())=='') {msg+="请输入电话!<br/>";}
		if($.trim($("#idCardNo").val())=='') {msg+="请输入身份证!<br/>";}
		 
		if(msg!='')
		{
			$.messager.alert('错误',msg);
			return false;
		}
		else
		{
			return true;
		}
	}
</script>
 
</head>
<body>
<div id="dataTable"></div>

<div id="wndAdd"  class="easyui-window">
		<div class="admin_search"
			style="width: 470px;height:240px">
			
			<form id="addForm" method="post">
			<input type="hidden" name="method" id="method" value="save"/>
			<input type="hidden" name="id" id="id"/>
			<table>
				<tr>
					<td class="textr w80">用户ID：</td>
					<td class="w180">
						<input id="userId" type="text" class="admin-input" name="userId"  style="width:150px;" readonly="readonly" />
						   
						       
					</td>
					<td class="textr w80">手机号：</td>
					<td>
						<input id="mobileNo" type="text" class="admin-input" name="mobileNo"  style="width:150px;"/> 
						</td>

					</tr>
					<tr>
						<td class="textr w80">
							 Email：
						</td>
						<td>
							<input class="admin-input" type="text" id="email" name="email"  style="width:150px;" 
							   data-options="editable:true,style:{width:150}" />
						</td>
						<td class="textr w80">姓名：</td>
						<td class="w180">
							<input id="name" class="admin-input" name="name" style="width:150px;" 
							   data-options="editable:true,style:{width:150}"/>
						</td>
					</tr>
					<tr>
						<td class="textr w80">性别：</td>
						<td >
							<select class="easyui-combobox admin-select" name="sex" id="sex" data-options="editable:false,valueField:'id',textField:'text',data:[{id:'m',text:'男',selected:true},{id:'f',text:'女'}]">
					</select>
						</td>	
						
						<td class="textr w80">年龄: </td>
						<td class="w180">
							<input type="text" id="age" name="age" class="admin-input" />
						</td>	
					</tr>	
					<tr>
					  <td class="textr w80">身份证号：</td>
						 <td class="w180">
						<input type="text" id="idCardNo" name="idCardNo" class="admin-input">
					  </td>	
					</tr>
					<tr>
					<td class="textr w80">地址：</td>
						<td class="w180" colspan="2">
						 <input type="text" id="address" name="address" class="admin-input">
						</td>
					</tr>							
					 
				</table>
				</form>
				<div style="text-align: center;">
				<a href="javascript:void(0);" id="bt_submit" class="easyui-linkbutton" data-options="iconCls:'icon-save'">保存</a>&nbsp;&nbsp;
				<a href="javascript:void(0);" id="bt_close" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'">关闭</a>
				</div>
			</div>
		</div>
</body>